package net.esj.basic.view;


import net.esj.basic.utils.ConstantsManager;
import net.esj.basic.utils.Validators;
import net.esj.basic.utils.view.BaseJsonMessage.MessageLevel;

public class ConstantAction extends BaseAction {

	private String id;
	private String key;
	
	public void load() {
		try {
			if (!Validators.isEmpty(id)) {
				writeString(ConstantsManager.getJSON(id).toString());
			}
		} catch (Exception e) {
			e.printStackTrace();
			writeBaseJsonMessage("", e.getMessage(), MessageLevel.ERROR);
		}
	}
	
	public void list(){
		try {
			if (!Validators.isEmpty(id)) {
				writeString(ConstantsManager.getJSON(id).toString());
			}
		} catch (Exception e) {
			e.printStackTrace();
			writeBaseJsonMessage("", e.getMessage(), MessageLevel.ERROR);
		}
	}

	public void getText(){
		try {
			if (!Validators.isEmpty(key) && !Validators.isEmpty(id)) {
				writeString(ConstantsManager.getValue(id, key));
			}
		} catch (Exception e) {
			e.printStackTrace();
			writeBaseJsonMessage("", e.getMessage(), MessageLevel.ERROR);
		}
	}
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

}
